package com.imooc.infra.mapping;

import com.imooc.business.domain.Collect;
import com.imooc.infra.repository.entity.TDataCenterCollect;
import com.imooc.module.collect.enums.CollectWayEnum;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

/**
 * @Author Tim
 * @Description:
 * @Version 1.0
 */
@Mapper(componentModel = "spring")
public interface CollectMapping {
    @Mapping(source = "collectWay", target = "collectWay", qualifiedByName = "toCollectWay")
    TDataCenterCollect toEntity(Collect collect);

    @Mapping(source = "collectWay", target = "collectWay", qualifiedByName = "toCollectWayEnum")
    Collect toVo(TDataCenterCollect collect);

    @Named("toCollectWay")
    default Integer toCollectWay(CollectWayEnum collectWayEnum){
        return collectWayEnum.getSourceValue();
    }

    @Named("toCollectWayEnum")
    default CollectWayEnum toCollectWay(Integer collectWay){
        return CollectWayEnum.parse(collectWay);
    }
}
